<?php
class HttpRequestToISO88591Filter extends sfFilter
{
	public function execute($filterChain)
	{
		// Execute this filter only once
		if ($this->isFirstCall())
		{
			$request = $this->getContext()->getRequest();
			if($request->isXmlHttpRequest()) {
				$ph = $request->getParameterHolder();
				$pars = $ph->getAll();
				$this->alteraRecursivo($pars);
			}
		}
		$filterChain->execute();
	}

	private function alteraRecursivo(&$par) {
		if(is_array($par)) {
			foreach($par as &$p) {
				$this->alteraRecursivo($p);
			}
		}
		else {
			$par = utf8_decode($par);
		}
	}
}
?>